package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("adminDishController")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     * @param dto
     * @return
     */
    @PostMapping
    public Result addDish(@RequestBody DishDTO dto){
        log.info("开启添加");
        return dishService.addDish(dto);
    }

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result pageDish(DishPageQueryDTO dishPageQueryDTO){
        return dishService.pageDish(dishPageQueryDTO);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteDish(@RequestParam List<Long> ids){
        return dishService.deleteDish(ids);
    }

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectId(@PathVariable Long id){
        return Result.success(dishService.selectId(id));
    }

    /**
     *修改菜品
     * @param dto
     * @return
     */
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dto){
        return dishService.updateDish(dto);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    public Result selectDish(@RequestParam(required = false)Long categoryId,@RequestParam(required = false) String name){
        return dishService.selectDish(categoryId,name);
    }


}
